<?php
/**
 * Static content controller.
 *
 * This file will render views from views/pages/
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */

App::uses('AppController', 'Controller');

/**
 * Static content controller
 *
 * Override this controller by placing a copy in controllers directory of an application
 *
 * @package       app.Controller
 * @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html
 */
class MembersController extends AppController {

/**
 * This controller does not use a model
 *
 * @var array
 */
	public $uses = array('Member');

	public function index(){
		$members=$this->Member->find('all');	
		//var_dump($members);
		$this->set("data",$members);
		
	}

	public function add(){
		if(!empty($this->data)){
			//var_dump($this->data);
			$this->Member->set($this->data);
			if($this->Member->validates()){
				if($this->Member->save($this->data)){
					$this->redirect('/members');
				}
				/*else{
					$errors = $this->Clients->invalidFields();
					var_dump($errors);
					$this->Session->setFlash(__("Some Error", true), 'flash', array('class' => 'alert alert-error'));
				}*/
			}
			else{
				$errors = $this->Member->validationErrors;
				//var_dump($errors);
				//$this->layout=false;
				//$this->render(false);	
				//$this->Session->setFlash(__("Error", true), 'flash', array('class' => 'alert alert-error'));
			}	
			//$this->layout=false;
			//$this->render(false);	
		}
	}

	public function edit($id){
		if (!empty($this->data)){
    	$this->Member->id = $id;
        if ($this->Member->save($this->data)) {
            //$this->Session->setFlash('Socio Actualizado.', 'flash', array('class' => 'thrill'));
            $this->redirect('/members');
        }
    }
    else {
        $this->request->data = $this->Member->findById($id);
    }

		$this->render("add");
	}

	public function delete($id){
		$this->layout=false;
		$this->render(false);
		$this->Member->delete($id);
		$this->redirect('/members');
	}
}
